#include <stdio.h>
#include <stdlib.h>

struct student
{
	int num;
	float score;
	struct student *pnext;
};

int main()
{
	struct student *p,*head,*t;
	p = (struct student *)malloc(sizeof(struct student));
	if (p == NULL)
	{
		printf("malloc fail\n");
			return 1;
	}
	printf("input student num:");
	scanf("%d",&p->num);
	printf("input student score:");
	scanf("%f",&p->score);
	head = t = p;

	while(1)
	{
		p = (struct student *)malloc(sizeof(struct student));
		if ( NULL == p )                //in if(use == not =)
		{
		//	free(head);
			printf("malloc fail\n");
			return 1;
		}
		printf("input student num:");
		scanf("%d",&p->num);
		if (p->num == -1)
		{
			t->pnext = NULL;	
			break ;
		}
		printf("input student score:");
		scanf("%f",&p->score);
		t->pnext = p;
		t = p ;
	}
	p = head;
	do
	{
		printf("num:%d  score: %4.2f\n",p->num,p->score);
		p = p->pnext;
	}while(p != NULL);

	return 0;
}
